package pl.edu.agh.jemo.evolution.operator.mutation.impl;

import javax.swing.JPanel;

import pl.edu.agh.jemo.evolution.common.JemoRandom;
import pl.edu.agh.jemo.evolution.specimen.Specimen;

public class RadialMutation extends ClassicMutation {

	protected Double radius = .5;
	
	@Override
	protected void mutate(Specimen specimen) {
		Double angle = JemoRandom.getRandom().nextDouble() * 2. * Math.PI;
		Double r = JemoRandom.getRandom().nextDouble() * radius;
		
		specimen.getGenotype()[0].fromDouble(specimen.getGenotype()[0].asDouble() + Math.cos(angle) * r);
		specimen.getGenotype()[1].fromDouble(specimen.getGenotype()[1].asDouble() + Math.sin(angle) * r);
	}

	public JPanel getConfigPanel() {
		return null;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(super.toString());
		sb.append(String.format("Mutation radius: %f\n", radius));
		return sb.toString();
	}
	
	public Double getRadius() {
		return radius;
	}
	
	public void setRadius(Double radius) {
		this.radius = radius;
	}
}
